﻿using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.UC.抖音出入库.Service;
using DXApplicationTangche.UC.抖音出入库.抖音UC;
using DXApplicationTangche.UC.面料审核.Service;
using DXApplicationTangche.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.抖音出入库
{
    public partial class Form抖音销售及备货统计 : DevExpress.XtraEditors.XtraForm
    {
        //页面需要的所有数据结构
        private DouyinOrderModel douyinOrderModel;

        public Form抖音销售及备货统计()
        {
            InitializeComponent();
        }

        private void dateTimePicker结束时间_CloseUp(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(this.dateTimePicker开始时间.Value.ToString("yyyy-MM-dd")))
            {
                this.刷新();
            }
        }

        private void dateTimePicker开始时间_CloseUp(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(this.dateTimePicker结束时间.Value.ToString("yyyy-MM-dd")))
            {
                this.刷新();
            }
        }
        private void 刷新()
        {
            //获取抖音订单一览，每次刷新生成所需DTO
            this.douyinOrderModel =
                new DouyinOrderModel(
                        this.dateTimePicker开始时间.Value.ToString("yyyy-MM-dd"),
                        this.dateTimePicker结束时间.Value.ToString("yyyy-MM-dd")
                    ).build();
            this.gridControl1.DataSource = this.douyinOrderModel.douyinOrderDTOs;
            this.gridView1.RefreshData();
            this.gridView1.ExpandAllGroups();

            this.刷新HOLD一览();
            this.刷新抖音下单数量一览();
        }

        private void simpleButton导入订单_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "csv|*.csv";
            ofd.Title = "请选择csv文件";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                //  csv导入
                面料审核Service.saveDouyinOrder("SSHIRT", "11", ofd.FileName);
                MessageBox.Show("csv上传成功");
            }
        }

        private void gridView抖音实际下单一览_DoubleClick(object sender, EventArgs e)
        {
            //从大的数据结构douyinOrderModel取要获取的dto：DouyinOrderRequestDTO
            new Form抖音修改下单数量(this.douyinOrderModel.douyinOrderRequestDTOs[this.gridView抖音实际下单一览.FocusedRowHandle]).ShowDialog();
            this.刷新抖音下单数量一览();
        }
        private void 刷新抖音下单数量一览()
        {
            this.gridControl抖音实际下单一览.DataSource = this.douyinOrderModel.douyinOrderRequestDTOs;
            this.gridView抖音实际下单一览.RefreshData();
        }
        private void 刷新HOLD一览()
        {
            this.gridControl2.DataSource = this.douyinOrderModel.douyinOrderDTOsHOLD;
            this.advBandedGridView1.RefreshData();
        }
        private void 添加至待下单ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //由HOLD添加至WAIT，计算所需订单数量，最后从HOLD移除
            this.douyinOrderModel = 
                douyinOrderModel
                .build(
                    //从大的数据结构douyinOrderModel取要获取的dto：DouyinOrderDTO
                    this.douyinOrderModel.douyinOrderDTOsHOLD[this.advBandedGridView1.FocusedRowHandle]
                    )
                .build();
            this.刷新HOLD一览();
            this.刷新抖音下单数量一览();
        }

        private void 修改商品信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new Form抖音下单修改商品信息(
                //从大的数据结构douyinOrderModel取要获取的dto：DouyinOrderDTO
                this.douyinOrderModel.douyinOrderDTOsHOLD[this.advBandedGridView1.FocusedRowHandle]
                ).ShowDialog();
            this.刷新HOLD一览();
        }
    }
}
